using DG.Tweening;
using GameFramework;
using UnityEngine;
using UnityEngine.UI;

namespace StarForce
{
    public class HPTextItem : CustomMono
    {
        [SerializeField]
        private Text m_Text = null;
        
        /// <summary>
        /// 飘字数据
        /// </summary>
        private HpTextData m_HpTextData;

        private Vector3 m_FromVector3;

        private Vector3 m_ToVector3;

        /// <summary>
        /// 初始化方法
        /// </summary>
        /// <param name="hpTextData">飘字数据</param>
        /// <param name="formPosition">生成位置</param>
        /// <param name="toVector3">移动位置位置</param>
        public void Init(HpTextData hpTextData , Vector3 formPosition,Vector3 toVector3)
        {
            gameObject.SetActive(true);
            transform.localScale = Vector3.one;
            m_HpTextData = hpTextData;
            //todo 根据不同的类型 渲染不同的飘字
            m_Text.text = m_HpTextData.Num.ToString();
            m_Text.color = Color.red;
            m_FromVector3 = formPosition;
            m_ToVector3 = toVector3;
            transform.localPosition = formPosition;
            
           
            //设置一个DOTween队列
            Sequence textMoveSequence = DOTween.Sequence();
            
            //设置Text移动和透明度的变化值
            Tweener textMove01 = transform.DOLocalMove(toVector3, 0.3f);

            Tweener textMove02 = transform.DOScale(Vector3.one * 1.5f, 0.3f);

            textMoveSequence.Append(textMove01);

            textMoveSequence.Join(textMove02);

            textMoveSequence.OnComplete(() =>
            {
                GameEntry.HPText.Hidden(this);
            });
        }
        
        /// <summary>
        /// 重置对象
        /// </summary>
        public void Reset()
        {
            gameObject.SetActive(false);
            ReferencePool.Release(m_HpTextData);
        }

        
    }
}